package com.binvshe.binvshe.mine.ticket;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.account.utils.FragmentUtils;
import com.binvshe.binvshe.common.http.DataRequestListener;
import com.binvshe.binvshe.common.http.MyHttpRequest;
import com.binvshe.binvshe.common.http.UrlCenter;
import com.binvshe.binvshe.common.image.IML;
import com.f2prateek.dart.Dart;
import com.f2prateek.dart.InjectExtra;
import com.pachong.android.baseuicomponent.fragment.BaseFragment;
import com.pachong.android.frameworkbase.utils.EasyToast;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShowQrCodeFragment extends BaseFragment {

    private static final String KEY_QRCODE_ID = "key_qrcode_id";

    @InjectExtra(KEY_QRCODE_ID)
    String mQrcodeId;

    @Bind(R.id.imgQrCode)
    ImageView mImgQrCode;

    public static ShowQrCodeFragment newInstance(String qrCodeId) {

        Bundle args = new Bundle();
        args.putString(KEY_QRCODE_ID, qrCodeId);
        ShowQrCodeFragment fragment = new ShowQrCodeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public ShowQrCodeFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        Dart.inject(this, getArguments());
        showToolbar();
        getCustomToolbar().setTitle("二维码");
        getCustomToolbar().enableBackButton().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                FragmentUtils.backStack(getActivity());
            }
        });
        getQrCode();
        return view;
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.frag_show_qr_code, null);
    }

    public void getQrCode() {
        String qrCodeImgUrl = String.format(UrlCenter.QRCODE, mQrcodeId);
        Log.e("getQrCode: ", qrCodeImgUrl);
        IML.load(getContext(), mImgQrCode, qrCodeImgUrl);
    }
}
